xref: /openbsd/gnu/usr.bin/binutils/gdb/inf-child.c (revision 11efff7f)
1*11efff7fSkettenis /* Default child (native) target interface, for GDB when running under
2*11efff7fSkettenis    Unix.
3*11efff7fSkettenis 
4*11efff7fSkettenis    Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996,
5*11efff7fSkettenis    1998, 1999, 2000, 2001, 2002, 2004 Free Software Foundation, Inc.
6*11efff7fSkettenis 
7*11efff7fSkettenis    This file is part of GDB.
8*11efff7fSkettenis 
9*11efff7fSkettenis    This program is free software; you can redistribute it and/or modify
10*11efff7fSkettenis    it under the terms of the GNU General Public License as published by
11*11efff7fSkettenis    the Free Software Foundation; either version 2 of the License, or
12*11efff7fSkettenis    (at your option) any later version.
13*11efff7fSkettenis 
14*11efff7fSkettenis    This program is distributed in the hope that it will be useful,
15*11efff7fSkettenis    but WITHOUT ANY WARRANTY; without even the implied warranty of
16*11efff7fSkettenis    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17*11efff7fSkettenis    GNU General Public License for more details.
18*11efff7fSkettenis 
19*11efff7fSkettenis    You should have received a copy of the GNU General Public License
20*11efff7fSkettenis    along with this program; if not, write to the Free Software
21*11efff7fSkettenis    Foundation, Inc., 59 Temple Place - Suite 330,
22*11efff7fSkettenis    Boston, MA 02111-1307, USA.  */
23*11efff7fSkettenis 
24*11efff7fSkettenis #include "defs.h"
25*11efff7fSkettenis #include "regcache.h"
26*11efff7fSkettenis #include "memattr.h"
27*11efff7fSkettenis #include "symtab.h"
28*11efff7fSkettenis #include "target.h"
29*11efff7fSkettenis #include "inferior.h"
30*11efff7fSkettenis #include "gdb_string.h"
31*11efff7fSkettenis 
32*11efff7fSkettenis /* Fetch register REGNUM from the inferior.  If REGNUM is -1, do this
33*11efff7fSkettenis    for all registers.  */
34*11efff7fSkettenis 
35*11efff7fSkettenis static void
inf_child_fetch_inferior_registers(int regnum)36*11efff7fSkettenis inf_child_fetch_inferior_registers (int regnum)
37*11efff7fSkettenis {
38*11efff7fSkettenis   if (regnum == -1)
39*11efff7fSkettenis     {
40*11efff7fSkettenis       for (regnum = 0; regnum < NUM_REGS; regnum++)
41*11efff7fSkettenis 	regcache_raw_supply (current_regcache, regnum, NULL);
42*11efff7fSkettenis     }
43*11efff7fSkettenis   else
44*11efff7fSkettenis     regcache_raw_supply (current_regcache, regnum, NULL);
45*11efff7fSkettenis }
46*11efff7fSkettenis 
47*11efff7fSkettenis /* Store register REGNUM back into the inferior.  If REGNUM is -1, do
48*11efff7fSkettenis    this for all registers (including the floating point registers).  */
49*11efff7fSkettenis 
50*11efff7fSkettenis static void
inf_child_store_inferior_registers(int regnum)51*11efff7fSkettenis inf_child_store_inferior_registers (int regnum)
52*11efff7fSkettenis {
53*11efff7fSkettenis }
54*11efff7fSkettenis 
55*11efff7fSkettenis static void
inf_child_post_attach(int pid)56*11efff7fSkettenis inf_child_post_attach (int pid)
57*11efff7fSkettenis {
58*11efff7fSkettenis   /* This version of Unix doesn't require a meaningful "post attach"
59*11efff7fSkettenis      operation by a debugger.  */
60*11efff7fSkettenis }
61*11efff7fSkettenis 
62*11efff7fSkettenis /* Get ready to modify the registers array.  On machines which store
63*11efff7fSkettenis    individual registers, this doesn't need to do anything.  On
64*11efff7fSkettenis    machines which store all the registers in one fell swoop, this
65*11efff7fSkettenis    makes sure that registers contains all the registers from the
66*11efff7fSkettenis    program being debugged.  */
67*11efff7fSkettenis 
68*11efff7fSkettenis static void
inf_child_prepare_to_store(void)69*11efff7fSkettenis inf_child_prepare_to_store (void)
70*11efff7fSkettenis {
71*11efff7fSkettenis }
72*11efff7fSkettenis 
73*11efff7fSkettenis static void
inf_child_open(char * arg,int from_tty)74*11efff7fSkettenis inf_child_open (char *arg, int from_tty)
75*11efff7fSkettenis {
76*11efff7fSkettenis   error ("Use the \"run\" command to start a Unix child process.");
77*11efff7fSkettenis }
78*11efff7fSkettenis 
79*11efff7fSkettenis static void
inf_child_post_startup_inferior(ptid_t ptid)80*11efff7fSkettenis inf_child_post_startup_inferior (ptid_t ptid)
81*11efff7fSkettenis {
82*11efff7fSkettenis   /* This version of Unix doesn't require a meaningful "post startup
83*11efff7fSkettenis      inferior" operation by a debugger.  */
84*11efff7fSkettenis }
85*11efff7fSkettenis 
86*11efff7fSkettenis static void
inf_child_acknowledge_created_inferior(int pid)87*11efff7fSkettenis inf_child_acknowledge_created_inferior (int pid)
88*11efff7fSkettenis {
89*11efff7fSkettenis   /* This version of Unix doesn't require a meaningful "acknowledge
90*11efff7fSkettenis      created inferior" operation by a debugger.  */
91*11efff7fSkettenis }
92*11efff7fSkettenis 
93*11efff7fSkettenis static int
inf_child_insert_fork_catchpoint(int pid)94*11efff7fSkettenis inf_child_insert_fork_catchpoint (int pid)
95*11efff7fSkettenis {
96*11efff7fSkettenis   /* This version of Unix doesn't support notification of fork
97*11efff7fSkettenis      events.  */
98*11efff7fSkettenis   return 0;
99*11efff7fSkettenis }
100*11efff7fSkettenis 
101*11efff7fSkettenis static int
inf_child_remove_fork_catchpoint(int pid)102*11efff7fSkettenis inf_child_remove_fork_catchpoint (int pid)
103*11efff7fSkettenis {
104*11efff7fSkettenis   /* This version of Unix doesn't support notification of fork
105*11efff7fSkettenis      events.  */
106*11efff7fSkettenis   return 0;
107*11efff7fSkettenis }
108*11efff7fSkettenis 
109*11efff7fSkettenis static int
inf_child_insert_vfork_catchpoint(int pid)110*11efff7fSkettenis inf_child_insert_vfork_catchpoint (int pid)
111*11efff7fSkettenis {
112*11efff7fSkettenis   /* This version of Unix doesn't support notification of vfork
113*11efff7fSkettenis      events.  */
114*11efff7fSkettenis   return 0;
115*11efff7fSkettenis }
116*11efff7fSkettenis 
117*11efff7fSkettenis static int
inf_child_remove_vfork_catchpoint(int pid)118*11efff7fSkettenis inf_child_remove_vfork_catchpoint (int pid)
119*11efff7fSkettenis {
120*11efff7fSkettenis   /* This version of Unix doesn't support notification of vfork
121*11efff7fSkettenis      events.  */
122*11efff7fSkettenis   return 0;
123*11efff7fSkettenis }
124*11efff7fSkettenis 
125*11efff7fSkettenis static int
inf_child_follow_fork(int follow_child)126*11efff7fSkettenis inf_child_follow_fork (int follow_child)
127*11efff7fSkettenis {
128*11efff7fSkettenis   /* This version of Unix doesn't support following fork or vfork
129*11efff7fSkettenis      events.  */
130*11efff7fSkettenis   return 0;
131*11efff7fSkettenis }
132*11efff7fSkettenis 
133*11efff7fSkettenis static int
inf_child_insert_exec_catchpoint(int pid)134*11efff7fSkettenis inf_child_insert_exec_catchpoint (int pid)
135*11efff7fSkettenis {
136*11efff7fSkettenis   /* This version of Unix doesn't support notification of exec
137*11efff7fSkettenis      events.  */
138*11efff7fSkettenis   return 0;
139*11efff7fSkettenis }
140*11efff7fSkettenis 
141*11efff7fSkettenis static int
inf_child_remove_exec_catchpoint(int pid)142*11efff7fSkettenis inf_child_remove_exec_catchpoint (int pid)
143*11efff7fSkettenis {
144*11efff7fSkettenis   /* This version of Unix doesn't support notification of exec
145*11efff7fSkettenis      events.  */
146*11efff7fSkettenis   return 0;
147*11efff7fSkettenis }
148*11efff7fSkettenis 
149*11efff7fSkettenis static int
inf_child_reported_exec_events_per_exec_call(void)150*11efff7fSkettenis inf_child_reported_exec_events_per_exec_call (void)
151*11efff7fSkettenis {
152*11efff7fSkettenis   /* This version of Unix doesn't support notification of exec
153*11efff7fSkettenis      events.  */
154*11efff7fSkettenis   return 1;
155*11efff7fSkettenis }
156*11efff7fSkettenis 
157*11efff7fSkettenis static int
inf_child_can_run(void)158*11efff7fSkettenis inf_child_can_run (void)
159*11efff7fSkettenis {
160*11efff7fSkettenis   return 1;
161*11efff7fSkettenis }
162*11efff7fSkettenis 
163*11efff7fSkettenis static struct symtab_and_line *
inf_child_enable_exception_callback(enum exception_event_kind kind,int enable)164*11efff7fSkettenis inf_child_enable_exception_callback (enum exception_event_kind kind,
165*11efff7fSkettenis 				     int enable)
166*11efff7fSkettenis {
167*11efff7fSkettenis   return (struct symtab_and_line *) NULL;
168*11efff7fSkettenis }
169*11efff7fSkettenis 
170*11efff7fSkettenis static struct exception_event_record *
inf_child_get_current_exception_event(void)171*11efff7fSkettenis inf_child_get_current_exception_event (void)
172*11efff7fSkettenis {
173*11efff7fSkettenis   return (struct exception_event_record *) NULL;
174*11efff7fSkettenis }
175*11efff7fSkettenis 
176*11efff7fSkettenis static char *
inf_child_pid_to_exec_file(int pid)177*11efff7fSkettenis inf_child_pid_to_exec_file (int pid)
178*11efff7fSkettenis {
179*11efff7fSkettenis   /* This version of Unix doesn't support translation of a process ID
180*11efff7fSkettenis      to the filename of the executable file.  */
181*11efff7fSkettenis   return NULL;
182*11efff7fSkettenis }
183*11efff7fSkettenis 
184*11efff7fSkettenis struct target_ops *
inf_child_target(void)185*11efff7fSkettenis inf_child_target (void)
186*11efff7fSkettenis {
187*11efff7fSkettenis   struct target_ops *t = XZALLOC (struct target_ops);
188*11efff7fSkettenis   t->to_shortname = "child";
189*11efff7fSkettenis   t->to_longname = "Unix child process";
190*11efff7fSkettenis   t->to_doc = "Unix child process (started by the \"run\" command).";
191*11efff7fSkettenis   t->to_open = inf_child_open;
192*11efff7fSkettenis   t->to_post_attach = inf_child_post_attach;
193*11efff7fSkettenis   t->to_fetch_registers = inf_child_fetch_inferior_registers;
194*11efff7fSkettenis   t->to_store_registers = inf_child_store_inferior_registers;
195*11efff7fSkettenis   t->to_prepare_to_store = inf_child_prepare_to_store;
196*11efff7fSkettenis   t->to_insert_breakpoint = memory_insert_breakpoint;
197*11efff7fSkettenis   t->to_remove_breakpoint = memory_remove_breakpoint;
198*11efff7fSkettenis   t->to_terminal_init = terminal_init_inferior;
199*11efff7fSkettenis   t->to_terminal_inferior = terminal_inferior;
200*11efff7fSkettenis   t->to_terminal_ours_for_output = terminal_ours_for_output;
201*11efff7fSkettenis   t->to_terminal_save_ours = terminal_save_ours;
202*11efff7fSkettenis   t->to_terminal_ours = terminal_ours;
203*11efff7fSkettenis   t->to_terminal_info = child_terminal_info;
204*11efff7fSkettenis   t->to_post_startup_inferior = inf_child_post_startup_inferior;
205*11efff7fSkettenis   t->to_acknowledge_created_inferior = inf_child_acknowledge_created_inferior;
206*11efff7fSkettenis   t->to_insert_fork_catchpoint = inf_child_insert_fork_catchpoint;
207*11efff7fSkettenis   t->to_remove_fork_catchpoint = inf_child_remove_fork_catchpoint;
208*11efff7fSkettenis   t->to_insert_vfork_catchpoint = inf_child_insert_vfork_catchpoint;
209*11efff7fSkettenis   t->to_remove_vfork_catchpoint = inf_child_remove_vfork_catchpoint;
210*11efff7fSkettenis   t->to_follow_fork = inf_child_follow_fork;
211*11efff7fSkettenis   t->to_insert_exec_catchpoint = inf_child_insert_exec_catchpoint;
212*11efff7fSkettenis   t->to_remove_exec_catchpoint = inf_child_remove_exec_catchpoint;
213*11efff7fSkettenis   t->to_reported_exec_events_per_exec_call =
214*11efff7fSkettenis     inf_child_reported_exec_events_per_exec_call;
215*11efff7fSkettenis   t->to_can_run = inf_child_can_run;
216*11efff7fSkettenis   t->to_enable_exception_callback = inf_child_enable_exception_callback;
217*11efff7fSkettenis   t->to_get_current_exception_event = inf_child_get_current_exception_event;
218*11efff7fSkettenis   t->to_pid_to_exec_file = inf_child_pid_to_exec_file;
219*11efff7fSkettenis   t->to_stratum = process_stratum;
220*11efff7fSkettenis   t->to_has_all_memory = 1;
221*11efff7fSkettenis   t->to_has_memory = 1;
222*11efff7fSkettenis   t->to_has_stack = 1;
223*11efff7fSkettenis   t->to_has_registers = 1;
224*11efff7fSkettenis   t->to_has_execution = 1;
225*11efff7fSkettenis   t->to_magic = OPS_MAGIC;
226*11efff7fSkettenis   return t;
227*11efff7fSkettenis }
228