1 /* Subroutines for handling an "inferior" (child) process as a target
3 Copyright 1990, 1991 Free Software Foundation, Inc.
4 Contributed by Cygnus Support.
6 This file is part of GDB.
8 GDB is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 1, or (at your option)
13 GDB is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GDB; see the file COPYING. If not, write to
20 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
25 #include "frame.h" /* required by inferior.h */
30 #include "ieee-float.h" /* Required by REGISTER_CONVERT_TO_XXX */
32 extern int fetch_inferior_registers();
33 extern int store_inferior_registers();
34 extern int child_xfer_memory();
35 extern int memory_insert_breakpoint(), memory_remove_breakpoint();
36 extern void terminal_init_inferior(), terminal_ours(), terminal_inferior();
37 extern void terminal_ours_for_output(), child_terminal_info();
38 extern void kill_inferior(), add_syms_addr_command();
39 extern struct value
*call_function_by_hand();
40 extern void child_resume();
41 extern void child_create_inferior();
42 extern void child_mourn_inferior();
43 extern void child_attach ();
45 /* Forward declaration */
46 extern struct target_ops child_ops
;
48 /* Wait for child to do something. Return pid of child, or -1 in case
49 of error; store status through argument pointer STATUS. */
59 if (pid
== -1) /* No more children to wait for */
61 fprintf (stderr
, "Child process unexpectedly missing.\n");
62 *status
= 42; /* Claim it exited with signal 42 */
65 } while (pid
!= inferior_pid
); /* Some other child died or stopped */
72 * takes a program previously attached to and detaches it.
73 * The program resumes execution and will no longer stop
74 * on signals, etc. We better not have left any breakpoints
75 * in the program or it'll die when it hits one. For this
76 * to work, it may be necessary for the process to have been
77 * previously attached. It *might* work if the program was
78 * started via the normal ptrace (PTRACE_TRACEME).
82 child_detach (args
, from_tty
)
91 char *exec_file
= get_exec_file (0);
94 printf ("Detaching program: %s pid %d\n",
95 exec_file
, inferior_pid
);
99 siggnal
= atoi (args
);
103 unpush_target (&child_ops
); /* Pop out of handling an inferior */
105 error ("This version of Unix does not support detaching a process.");
109 /* Get ready to modify the registers array. On machines which store
110 individual registers, this doesn't need to do anything. On machines
111 which store all the registers in one fell swoop, this makes sure
112 that registers contains all the registers from the program being
116 child_prepare_to_store ()
118 #ifdef CHILD_PREPARE_TO_STORE
119 CHILD_PREPARE_TO_STORE ();
123 /* Convert data from raw format for register REGNUM
124 to virtual format for register REGNUM. */
127 host_convert_to_virtual (regnum
, from
, to
)
132 REGISTER_CONVERT_TO_VIRTUAL (regnum
, from
, to
);
135 /* Convert data from virtual format for register REGNUM
136 to raw format for register REGNUM. */
139 host_convert_from_virtual (regnum
, from
, to
)
144 REGISTER_CONVERT_TO_RAW (regnum
, from
, to
);
147 /* Print status information about what we're accessing. */
152 printf ("\tUsing the running image of %s process %d.\n",
153 attach_flag
? "attached": "child", inferior_pid
);
157 child_open (arg
, from_tty
)
161 error ("Use the \"run\" command to start a Unix child process.");
164 struct target_ops child_ops
= {
165 "child", "Unix child process",
166 "Unix child process (started by the \"run\" command).",
167 child_open
, 0, /* open, close */
168 child_attach
, child_detach
,
171 fetch_inferior_registers
, store_inferior_registers
,
172 child_prepare_to_store
,
173 host_convert_to_virtual
, host_convert_from_virtual
,
174 child_xfer_memory
, child_files_info
,
175 memory_insert_breakpoint
, memory_remove_breakpoint
,
176 terminal_init_inferior
, terminal_inferior
,
177 terminal_ours_for_output
, terminal_ours
, child_terminal_info
,
178 kill_inferior
, 0, add_syms_addr_command
, /* load */
179 call_function_by_hand
,
180 0, /* lookup_symbol */
181 child_create_inferior
, child_mourn_inferior
,
182 process_stratum
, 0, /* next */
183 1, 1, 1, 1, 1, /* all mem, mem, stack, regs, exec */
184 OPS_MAGIC
, /* Always the last thing */
188 _initialize_inftarg ()
190 add_target (&child_ops
);