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