* dwarf2dbg.c (scale_addr_delta): Correct parameter. Move prototype
[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
c906108c
SS
107/* Wait for child to do something. Return pid of child, or -1 in case
108 of error; store status through argument pointer OURSTATUS. */
109
39f77062
KB
110static ptid_t
111child_wait (ptid_t ptid, struct target_waitstatus *ourstatus)
c906108c
SS
112{
113 int save_errno;
114 int status;
7a292a7a 115 char *execd_pathname = NULL;
c5aa993b
JM
116 int exit_status;
117 int related_pid;
118 int syscall_id;
119 enum target_waitkind kind;
39f77062 120 int pid;
c906108c 121
c5aa993b
JM
122 do
123 {
124 set_sigint_trap (); /* Causes SIGINT to be passed on to the
125 attached process. */
126 set_sigio_trap ();
c906108c 127
39f77062 128 pid = ptrace_wait (inferior_ptid, &status);
c906108c 129
c5aa993b 130 save_errno = errno;
c906108c 131
c5aa993b 132 clear_sigio_trap ();
c906108c 133
c5aa993b 134 clear_sigint_trap ();
c906108c 135
c5aa993b
JM
136 if (pid == -1)
137 {
138 if (save_errno == EINTR)
139 continue;
c906108c 140
c5aa993b
JM
141 fprintf_unfiltered (gdb_stderr, "Child process unexpectedly missing: %s.\n",
142 safe_strerror (save_errno));
c906108c 143
c5aa993b
JM
144 /* Claim it exited with unknown signal. */
145 ourstatus->kind = TARGET_WAITKIND_SIGNALLED;
146 ourstatus->value.sig = TARGET_SIGNAL_UNKNOWN;
39f77062 147 return pid_to_ptid (-1);
c5aa993b 148 }
c906108c 149
c5aa993b 150 /* Did it exit?
c906108c 151 */
c5aa993b
JM
152 if (target_has_exited (pid, status, &exit_status))
153 {
154 /* ??rehrauer: For now, ignore this. */
155 continue;
156 }
157
39f77062 158 if (!target_thread_alive (pid_to_ptid (pid)))
c5aa993b
JM
159 {
160 ourstatus->kind = TARGET_WAITKIND_SPURIOUS;
39f77062 161 return pid_to_ptid (pid);
c5aa993b 162 }
47932f85 163 } while (pid != PIDGET (inferior_ptid)); /* Some other child died or stopped */
c906108c
SS
164
165 store_waitstatus (ourstatus, status);
39f77062 166 return pid_to_ptid (pid);
c906108c
SS
167}
168#endif /* CHILD_WAIT */
169
170#if !defined(CHILD_POST_WAIT)
171void
39f77062 172child_post_wait (ptid_t ptid, int wait_status)
c906108c
SS
173{
174 /* This version of Unix doesn't require a meaningful "post wait"
175 operation.
c5aa993b 176 */
c906108c
SS
177}
178#endif
c5aa993b 179
c906108c
SS
180
181#ifndef CHILD_THREAD_ALIVE
182
183/* Check to see if the given thread is alive.
184
185 FIXME: Is kill() ever the right way to do this? I doubt it, but
186 for now we're going to try and be compatable with the old thread
187 code. */
188int
39f77062 189child_thread_alive (ptid_t ptid)
c906108c 190{
39f77062
KB
191 pid_t pid = PIDGET (ptid);
192
c906108c
SS
193 return (kill (pid, 0) != -1);
194}
195
196#endif
197
198static void
fba45db2 199child_attach_to_process (char *args, int from_tty, int after_fork)
c906108c
SS
200{
201 if (!args)
202 error_no_arg ("process-id to attach");
203
204#ifndef ATTACH_DETACH
205 error ("Can't attach to a process on this machine.");
206#else
207 {
208 char *exec_file;
209 int pid;
210 char *dummy;
211
212 dummy = args;
213 pid = strtol (args, &dummy, 0);
214 /* Some targets don't set errno on errors, grrr! */
215 if ((pid == 0) && (args == dummy))
216 error ("Illegal process-id: %s\n", args);
217
c5aa993b 218 if (pid == getpid ()) /* Trying to masturbate? */
c906108c
SS
219 error ("I refuse to debug myself!");
220
221 if (from_tty)
222 {
223 exec_file = (char *) get_exec_file (0);
224
225 if (after_fork)
c5aa993b 226 printf_unfiltered ("Attaching after fork to %s\n",
39f77062 227 target_pid_to_str (pid_to_ptid (pid)));
c906108c
SS
228 else if (exec_file)
229 printf_unfiltered ("Attaching to program: %s, %s\n", exec_file,
39f77062 230 target_pid_to_str (pid_to_ptid (pid)));
c5aa993b 231 else
39f77062
KB
232 printf_unfiltered ("Attaching to %s\n",
233 target_pid_to_str (pid_to_ptid (pid)));
c906108c
SS
234
235 gdb_flush (gdb_stdout);
236 }
237
238 if (!after_fork)
239 attach (pid);
240 else
241 REQUIRE_ATTACH (pid);
242
39f77062 243 inferior_ptid = pid_to_ptid (pid);
c906108c
SS
244 push_target (&child_ops);
245 }
c5aa993b 246#endif /* ATTACH_DETACH */
c906108c
SS
247}
248
249
250/* Attach to process PID, then initialize for debugging it. */
251
252static void
fba45db2 253child_attach (char *args, int from_tty)
c906108c
SS
254{
255 child_attach_to_process (args, from_tty, 0);
256}
257
258#if !defined(CHILD_POST_ATTACH)
259void
fba45db2 260child_post_attach (int pid)
c906108c
SS
261{
262 /* This version of Unix doesn't require a meaningful "post attach"
263 operation by a debugger. */
264}
265#endif
266
267static void
fba45db2 268child_require_attach (char *args, int from_tty)
c906108c
SS
269{
270 child_attach_to_process (args, from_tty, 1);
c5aa993b 271}
c906108c
SS
272
273static void
fba45db2 274child_detach_from_process (int pid, char *args, int from_tty, int after_fork)
c906108c
SS
275{
276#ifdef ATTACH_DETACH
277 {
278 int siggnal = 0;
279
280 if (from_tty)
281 {
282 char *exec_file = get_exec_file (0);
283 if (exec_file == 0)
284 exec_file = "";
c5aa993b
JM
285 if (after_fork)
286 printf_unfiltered ("Detaching after fork from %s\n",
39f77062 287 target_pid_to_str (pid_to_ptid (pid)));
c5aa993b 288 else
c906108c 289 printf_unfiltered ("Detaching from program: %s, %s\n", exec_file,
39f77062 290 target_pid_to_str (pid_to_ptid (pid)));
c906108c
SS
291 gdb_flush (gdb_stdout);
292 }
293 if (args)
294 siggnal = atoi (args);
295
296 if (!after_fork)
297 detach (siggnal);
298 else
299 REQUIRE_DETACH (pid, siggnal);
300 }
301#else
302 error ("This version of Unix does not support detaching a process.");
303#endif
304}
305
306/* Take a program previously attached to and detaches it.
307 The program resumes execution and will no longer stop
308 on signals, etc. We'd better not have left any breakpoints
309 in the program or it'll die when it hits one. For this
310 to work, it may be necessary for the process to have been
311 previously attached. It *might* work if the program was
312 started via the normal ptrace (PTRACE_TRACEME). */
313
314static void
fba45db2 315child_detach (char *args, int from_tty)
c906108c 316{
39f77062
KB
317 child_detach_from_process (PIDGET (inferior_ptid), args, from_tty, 0);
318 inferior_ptid = null_ptid;
c906108c
SS
319 unpush_target (&child_ops);
320}
321
322static void
fba45db2 323child_require_detach (int pid, char *args, int from_tty)
c906108c
SS
324{
325 child_detach_from_process (pid, args, from_tty, 1);
326}
327
328
329/* Get ready to modify the registers array. On machines which store
330 individual registers, this doesn't need to do anything. On machines
331 which store all the registers in one fell swoop, this makes sure
332 that registers contains all the registers from the program being
333 debugged. */
334
335static void
fba45db2 336child_prepare_to_store (void)
c906108c
SS
337{
338#ifdef CHILD_PREPARE_TO_STORE
339 CHILD_PREPARE_TO_STORE ();
340#endif
341}
342
343/* Print status information about what we're accessing. */
344
345static void
fba45db2 346child_files_info (struct target_ops *ignore)
c906108c
SS
347{
348 printf_unfiltered ("\tUsing the running image of %s %s.\n",
39f77062 349 attach_flag ? "attached" : "child", target_pid_to_str (inferior_ptid));
c906108c
SS
350}
351
352/* ARGSUSED */
353static void
fba45db2 354child_open (char *arg, int from_tty)
c906108c
SS
355{
356 error ("Use the \"run\" command to start a Unix child process.");
357}
358
359/* Stub function which causes the inferior that runs it, to be ptrace-able
360 by its parent process. */
361
362static void
fba45db2 363ptrace_me (void)
c906108c
SS
364{
365 /* "Trace me, Dr. Memory!" */
366 call_ptrace (0, 0, (PTRACE_ARG3_TYPE) 0, 0);
367}
368
369/* Stub function which causes the GDB that runs it, to start ptrace-ing
370 the child process. */
371
c5aa993b 372static void
fba45db2 373ptrace_him (int pid)
c906108c
SS
374{
375 push_target (&child_ops);
376
377 /* On some targets, there must be some explicit synchronization
378 between the parent and child processes after the debugger
379 forks, and before the child execs the debuggee program. This
380 call basically gives permission for the child to exec.
c5aa993b 381 */
c906108c
SS
382
383 target_acknowledge_created_inferior (pid);
384
385 /* START_INFERIOR_TRAPS_EXPECTED is defined in inferior.h,
386 * and will be 1 or 2 depending on whether we're starting
387 * without or with a shell.
388 */
389 startup_inferior (START_INFERIOR_TRAPS_EXPECTED);
390
391 /* On some targets, there must be some explicit actions taken after
392 the inferior has been started up.
c5aa993b 393 */
39f77062 394 target_post_startup_inferior (pid_to_ptid (pid));
c906108c
SS
395}
396
39f77062 397/* Start an inferior Unix child process and sets inferior_ptid to its pid.
c906108c
SS
398 EXEC_FILE is the file to run.
399 ALLARGS is a string containing the arguments to the program.
400 ENV is the environment vector to pass. Errors reported with error(). */
401
402static void
fba45db2 403child_create_inferior (char *exec_file, char *allargs, char **env)
c906108c 404{
c906108c 405#ifdef HPUXHPPA
c906108c
SS
406 fork_inferior (exec_file, allargs, env, ptrace_me, ptrace_him, pre_fork_inferior, NULL);
407#else
c5aa993b 408 fork_inferior (exec_file, allargs, env, ptrace_me, ptrace_him, NULL, NULL);
c906108c
SS
409#endif
410 /* We are at the first instruction we care about. */
411 /* Pedal to the metal... */
2acceee2 412 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_0, 0);
c906108c
SS
413}
414
415#if !defined(CHILD_POST_STARTUP_INFERIOR)
416void
39f77062 417child_post_startup_inferior (ptid_t ptid)
c906108c
SS
418{
419 /* This version of Unix doesn't require a meaningful "post startup inferior"
420 operation by a debugger.
c5aa993b 421 */
c906108c
SS
422}
423#endif
424
425#if !defined(CHILD_ACKNOWLEDGE_CREATED_INFERIOR)
426void
fba45db2 427child_acknowledge_created_inferior (int pid)
c906108c
SS
428{
429 /* This version of Unix doesn't require a meaningful "acknowledge created inferior"
430 operation by a debugger.
c5aa993b 431 */
c906108c
SS
432}
433#endif
434
435
c906108c
SS
436#if !defined(CHILD_INSERT_FORK_CATCHPOINT)
437int
fba45db2 438child_insert_fork_catchpoint (int pid)
c906108c
SS
439{
440 /* This version of Unix doesn't support notification of fork events. */
441 return 0;
442}
443#endif
444
445#if !defined(CHILD_REMOVE_FORK_CATCHPOINT)
446int
fba45db2 447child_remove_fork_catchpoint (int pid)
c906108c
SS
448{
449 /* This version of Unix doesn't support notification of fork events. */
450 return 0;
451}
452#endif
453
454#if !defined(CHILD_INSERT_VFORK_CATCHPOINT)
455int
fba45db2 456child_insert_vfork_catchpoint (int pid)
c906108c
SS
457{
458 /* This version of Unix doesn't support notification of vfork events. */
459 return 0;
460}
461#endif
462
463#if !defined(CHILD_REMOVE_VFORK_CATCHPOINT)
464int
fba45db2 465child_remove_vfork_catchpoint (int pid)
c906108c
SS
466{
467 /* This version of Unix doesn't support notification of vfork events. */
468 return 0;
469}
470#endif
471
c906108c
SS
472#if !defined(CHILD_POST_FOLLOW_VFORK)
473void
fba45db2
KB
474child_post_follow_vfork (int parent_pid, int followed_parent, int child_pid,
475 int followed_child)
c906108c
SS
476{
477 /* This version of Unix doesn't require a meaningful "post follow vfork"
478 operation by a clone debugger.
c5aa993b 479 */
c906108c
SS
480}
481#endif
482
483#if !defined(CHILD_INSERT_EXEC_CATCHPOINT)
484int
fba45db2 485child_insert_exec_catchpoint (int pid)
c906108c
SS
486{
487 /* This version of Unix doesn't support notification of exec events. */
488 return 0;
489}
490#endif
491
492#if !defined(CHILD_REMOVE_EXEC_CATCHPOINT)
493int
fba45db2 494child_remove_exec_catchpoint (int pid)
c906108c
SS
495{
496 /* This version of Unix doesn't support notification of exec events. */
497 return 0;
498}
499#endif
500
c906108c
SS
501#if !defined(CHILD_REPORTED_EXEC_EVENTS_PER_EXEC_CALL)
502int
fba45db2 503child_reported_exec_events_per_exec_call (void)
c906108c
SS
504{
505 /* This version of Unix doesn't support notification of exec events.
c5aa993b 506 */
c906108c
SS
507 return 1;
508}
509#endif
510
c906108c
SS
511#if !defined(CHILD_HAS_EXITED)
512int
fba45db2 513child_has_exited (int pid, int wait_status, int *exit_status)
c906108c
SS
514{
515 if (WIFEXITED (wait_status))
516 {
517 *exit_status = WEXITSTATUS (wait_status);
518 return 1;
519 }
520
521 if (WIFSIGNALED (wait_status))
522 {
c5aa993b 523 *exit_status = 0; /* ?? Don't know what else to say here. */
c906108c
SS
524 return 1;
525 }
526
527 /* ?? Do we really need to consult the event state, too? Assume the
c5aa993b 528 wait_state alone suffices.
c906108c
SS
529 */
530 return 0;
531}
532#endif
533
534
535static void
fba45db2 536child_mourn_inferior (void)
c906108c 537{
c906108c 538 unpush_target (&child_ops);
c906108c
SS
539 generic_mourn_inferior ();
540}
541
542static int
fba45db2 543child_can_run (void)
c906108c
SS
544{
545 /* This variable is controlled by modules that sit atop inftarg that may layer
546 their own process structure atop that provided here. hpux-thread.c does
547 this because of the Hpux user-mode level thread model. */
548
549 return !child_suppress_run;
550}
551
552/* Send a SIGINT to the process group. This acts just like the user typed a
553 ^C on the controlling terminal.
554
555 XXX - This may not be correct for all systems. Some may want to use
556 killpg() instead of kill (-pgrp). */
557
558static void
fba45db2 559child_stop (void)
c906108c
SS
560{
561 extern pid_t inferior_process_group;
562
563 kill (-inferior_process_group, SIGINT);
564}
565
566#if !defined(CHILD_ENABLE_EXCEPTION_CALLBACK)
567struct symtab_and_line *
fba45db2 568child_enable_exception_callback (enum exception_event_kind kind, int enable)
c906108c
SS
569{
570 return (struct symtab_and_line *) NULL;
571}
572#endif
573
574#if !defined(CHILD_GET_CURRENT_EXCEPTION_EVENT)
575struct exception_event_record *
fba45db2 576child_get_current_exception_event (void)
c906108c
SS
577{
578 return (struct exception_event_record *) NULL;
579}
580#endif
581
582
583#if !defined(CHILD_PID_TO_EXEC_FILE)
584char *
fba45db2 585child_pid_to_exec_file (int pid)
c906108c
SS
586{
587 /* This version of Unix doesn't support translation of a process ID
588 to the filename of the executable file.
c5aa993b 589 */
c906108c
SS
590 return NULL;
591}
592#endif
593
594char *
fba45db2 595child_core_file_to_sym_file (char *core)
c906108c
SS
596{
597 /* The target stratum for a running executable need not support
598 this operation.
c5aa993b 599 */
c906108c
SS
600 return NULL;
601}
c5aa993b 602\f
c906108c 603
ed9a39eb
JM
604#if !defined(CHILD_PID_TO_STR)
605char *
39f77062 606child_pid_to_str (ptid_t ptid)
ed9a39eb 607{
39f77062 608 return normal_pid_to_str (ptid);
ed9a39eb
JM
609}
610#endif
c906108c 611
c906108c 612static void
fba45db2 613init_child_ops (void)
c906108c
SS
614{
615 child_ops.to_shortname = "child";
616 child_ops.to_longname = "Unix child process";
617 child_ops.to_doc = "Unix child process (started by the \"run\" command).";
618 child_ops.to_open = child_open;
619 child_ops.to_attach = child_attach;
620 child_ops.to_post_attach = child_post_attach;
621 child_ops.to_require_attach = child_require_attach;
622 child_ops.to_detach = child_detach;
623 child_ops.to_require_detach = child_require_detach;
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;
631 child_ops.to_files_info = child_files_info;
632 child_ops.to_insert_breakpoint = memory_insert_breakpoint;
633 child_ops.to_remove_breakpoint = memory_remove_breakpoint;
634 child_ops.to_terminal_init = terminal_init_inferior;
635 child_ops.to_terminal_inferior = terminal_inferior;
636 child_ops.to_terminal_ours_for_output = terminal_ours_for_output;
a790ad35 637 child_ops.to_terminal_save_ours = terminal_save_ours;
c906108c
SS
638 child_ops.to_terminal_ours = terminal_ours;
639 child_ops.to_terminal_info = child_terminal_info;
640 child_ops.to_kill = kill_inferior;
641 child_ops.to_create_inferior = child_create_inferior;
642 child_ops.to_post_startup_inferior = child_post_startup_inferior;
643 child_ops.to_acknowledge_created_inferior = child_acknowledge_created_inferior;
c906108c
SS
644 child_ops.to_insert_fork_catchpoint = child_insert_fork_catchpoint;
645 child_ops.to_remove_fork_catchpoint = child_remove_fork_catchpoint;
646 child_ops.to_insert_vfork_catchpoint = child_insert_vfork_catchpoint;
647 child_ops.to_remove_vfork_catchpoint = child_remove_vfork_catchpoint;
c906108c
SS
648 child_ops.to_post_follow_vfork = child_post_follow_vfork;
649 child_ops.to_insert_exec_catchpoint = child_insert_exec_catchpoint;
650 child_ops.to_remove_exec_catchpoint = child_remove_exec_catchpoint;
c906108c 651 child_ops.to_reported_exec_events_per_exec_call = child_reported_exec_events_per_exec_call;
c906108c
SS
652 child_ops.to_has_exited = child_has_exited;
653 child_ops.to_mourn_inferior = child_mourn_inferior;
654 child_ops.to_can_run = child_can_run;
655 child_ops.to_thread_alive = child_thread_alive;
ed9a39eb 656 child_ops.to_pid_to_str = child_pid_to_str;
c906108c
SS
657 child_ops.to_stop = child_stop;
658 child_ops.to_enable_exception_callback = child_enable_exception_callback;
659 child_ops.to_get_current_exception_event = child_get_current_exception_event;
660 child_ops.to_pid_to_exec_file = child_pid_to_exec_file;
c906108c
SS
661 child_ops.to_stratum = process_stratum;
662 child_ops.to_has_all_memory = 1;
663 child_ops.to_has_memory = 1;
664 child_ops.to_has_stack = 1;
665 child_ops.to_has_registers = 1;
666 child_ops.to_has_execution = 1;
667 child_ops.to_magic = OPS_MAGIC;
668}
669
be4d1333
MS
670/* Take over the 'find_mapped_memory' vector from inftarg.c. */
671extern void
672inftarg_set_find_memory_regions (int (*func) (int (*) (CORE_ADDR,
673 unsigned long,
674 int, int, int,
675 void *),
676 void *))
677{
678 child_ops.to_find_memory_regions = func;
679}
680
681/* Take over the 'make_corefile_notes' vector from inftarg.c. */
682extern void
683inftarg_set_make_corefile_notes (char * (*func) (bfd *, int *))
684{
685 child_ops.to_make_corefile_notes = func;
686}
687
c906108c 688void
fba45db2 689_initialize_inftarg (void)
c906108c
SS
690{
691#ifdef HAVE_OPTIONAL_PROC_FS
692 char procname[32];
693 int fd;
694
695 /* If we have an optional /proc filesystem (e.g. under OSF/1),
696 don't add ptrace support if we can access the running GDB via /proc. */
697#ifndef PROC_NAME_FMT
698#define PROC_NAME_FMT "/proc/%05d"
699#endif
700 sprintf (procname, PROC_NAME_FMT, getpid ());
701 if ((fd = open (procname, O_RDONLY)) >= 0)
702 {
703 close (fd);
704 return;
705 }
706#endif
707
708 init_child_ops ();
709 add_target (&child_ops);
710}
This page took 0.25738 seconds and 4 git commands to generate.