* configure.in: removed target_dependent line.
[deliverable/binutils-gdb.git] / gdb / inftarg.c
CommitLineData
bd5635a1
RP
1/* Subroutines for handling an "inferior" (child) process as a target
2 for debugging, in GDB.
3 Copyright 1990, 1991 Free Software Foundation, Inc.
4 Contributed by Cygnus Support.
5
6This file is part of GDB.
7
dcc8abce 8This program is free software; you can redistribute it and/or modify
bd5635a1 9it under the terms of the GNU General Public License as published by
dcc8abce
JG
10the Free Software Foundation; either version 2 of the License, or
11(at your option) any later version.
bd5635a1 12
dcc8abce 13This program is distributed in the hope that it will be useful,
bd5635a1
RP
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License
dcc8abce
JG
19along with this program; if not, write to the Free Software
20Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
bd5635a1 21
bd5635a1 22#include "defs.h"
bd5635a1
RP
23#include "frame.h" /* required by inferior.h */
24#include "inferior.h"
25#include "target.h"
26#include "wait.h"
27#include "gdbcore.h"
28#include "ieee-float.h" /* Required by REGISTER_CONVERT_TO_XXX */
29
dcc8abce
JG
30static void
31child_prepare_to_store PARAMS ((void));
32
33static int
34child_wait PARAMS ((int *));
35
36static void
37child_open PARAMS ((char *, int));
38
39static void
40child_files_info PARAMS ((struct target_ops *));
41
42static void
43child_detach PARAMS ((char *, int));
bd5635a1
RP
44
45/* Forward declaration */
46extern struct target_ops child_ops;
47
48/* Wait for child to do something. Return pid of child, or -1 in case
49 of error; store status through argument pointer STATUS. */
50
dcc8abce 51static int
bd5635a1
RP
52child_wait (status)
53 int *status;
54{
55 int pid;
56
57 do {
dcc8abce
JG
58#ifdef USE_PROC_FS
59 pid = proc_wait (status);
60#else
bd5635a1 61 pid = wait (status);
dcc8abce 62#endif
bd5635a1
RP
63 if (pid == -1) /* No more children to wait for */
64 {
65 fprintf (stderr, "Child process unexpectedly missing.\n");
66 *status = 42; /* Claim it exited with signal 42 */
67 return -1;
68 }
69 } while (pid != inferior_pid); /* Some other child died or stopped */
70 return pid;
71}
72
73
74/*
75 * child_detach()
76 * takes a program previously attached to and detaches it.
77 * The program resumes execution and will no longer stop
78 * on signals, etc. We better not have left any breakpoints
79 * in the program or it'll die when it hits one. For this
80 * to work, it may be necessary for the process to have been
81 * previously attached. It *might* work if the program was
82 * started via the normal ptrace (PTRACE_TRACEME).
83 */
84
85static void
86child_detach (args, from_tty)
87 char *args;
88 int from_tty;
89{
90 int siggnal = 0;
91
92#ifdef ATTACH_DETACH
93 if (from_tty)
94 {
95 char *exec_file = get_exec_file (0);
96 if (exec_file == 0)
97 exec_file = "";
98 printf ("Detaching program: %s pid %d\n",
99 exec_file, inferior_pid);
100 fflush (stdout);
101 }
102 if (args)
103 siggnal = atoi (args);
104
105 detach (siggnal);
106 inferior_pid = 0;
107 unpush_target (&child_ops); /* Pop out of handling an inferior */
108#else
109 error ("This version of Unix does not support detaching a process.");
110#endif
111}
112
113/* Get ready to modify the registers array. On machines which store
114 individual registers, this doesn't need to do anything. On machines
115 which store all the registers in one fell swoop, this makes sure
116 that registers contains all the registers from the program being
117 debugged. */
118
dcc8abce 119static void
bd5635a1
RP
120child_prepare_to_store ()
121{
122#ifdef CHILD_PREPARE_TO_STORE
123 CHILD_PREPARE_TO_STORE ();
124#endif
125}
126
bd5635a1
RP
127/* Print status information about what we're accessing. */
128
129static void
dcc8abce
JG
130child_files_info (ignore)
131 struct target_ops *ignore;
bd5635a1
RP
132{
133 printf ("\tUsing the running image of %s process %d.\n",
134 attach_flag? "attached": "child", inferior_pid);
135}
136
e1ce8aa5 137/* ARGSUSED */
70dcc196
JK
138static void
139child_open (arg, from_tty)
140 char *arg;
141 int from_tty;
142{
143 error ("Use the \"run\" command to start a Unix child process.");
144}
145
bd5635a1 146struct target_ops child_ops = {
dcc8abce
JG
147 "child", /* to_shortname */
148 "Unix child process", /* to_longname */
149 "Unix child process (started by the \"run\" command).", /* to_doc */
150 child_open, /* to_open */
151 0, /* to_close */
152 child_attach, /* to_attach */
153 child_detach, /* to_detach */
154 child_resume, /* to_resume */
155 child_wait, /* to_wait */
156 fetch_inferior_registers, /* to_fetch_registers */
157 store_inferior_registers, /* to_store_registers */
158 child_prepare_to_store, /* to_prepare_to_store */
159 child_xfer_memory, /* to_xfer_memory */
160 child_files_info, /* to_files_info */
161 memory_insert_breakpoint, /* to_insert_breakpoint */
162 memory_remove_breakpoint, /* to_remove_breakpoint */
163 terminal_init_inferior, /* to_terminal_init */
164 terminal_inferior, /* to_terminal_inferior */
165 terminal_ours_for_output, /* to_terminal_ours_for_output */
166 terminal_ours, /* to_terminal_ours */
167 child_terminal_info, /* to_terminal_info */
168 kill_inferior, /* to_kill */
169 0, /* to_load */
170 0, /* to_lookup_symbol */
171 child_create_inferior, /* to_create_inferior */
172 child_mourn_inferior, /* to_mourn_inferior */
173 process_stratum, /* to_stratum */
174 0, /* to_next */
175 1, /* to_has_all_memory */
176 1, /* to_has_memory */
177 1, /* to_has_stack */
178 1, /* to_has_registers */
179 1, /* to_has_execution */
180 0, /* sections */
181 0, /* sections_end */
182 OPS_MAGIC /* to_magic */
bd5635a1
RP
183};
184
185void
186_initialize_inftarg ()
187{
188 add_target (&child_ops);
189}
This page took 0.074378 seconds and 4 git commands to generate.