* xcoffexec.c (exec_ops): child_attach and child_create_inferior
[deliverable/binutils-gdb.git] / gdb / target.h
1 /* Interface between GDB and target environments, including files and processes
2 Copyright 1990, 1991, 1992 Free Software Foundation, Inc.
3 Contributed by Cygnus Support. Written by John Gilmore.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
20
21 #if !defined (TARGET_H)
22 #define TARGET_H
23
24 /* This include file defines the interface between the main part
25 of the debugger, and the part which is target-specific, or
26 specific to the communications interface between us and the
27 target.
28
29 A TARGET is an interface between the debugger and a particular
30 kind of file or process. Targets can be STACKED in STRATA,
31 so that more than one target can potentially respond to a request.
32 In particular, memory accesses will walk down the stack of targets
33 until they find a target that is interested in handling that particular
34 address. STRATA are artificial boundaries on the stack, within
35 which particular kinds of targets live. Strata exist so that
36 people don't get confused by pushing e.g. a process target and then
37 a file target, and wondering why they can't see the current values
38 of variables any more (the file target is handling them and they
39 never get to the process target). So when you push a file target,
40 it goes into the file stratum, which is always below the process
41 stratum. */
42
43 #include "bfd.h"
44
45 enum strata {
46 dummy_stratum, /* The lowest of the low */
47 file_stratum, /* Executable files, etc */
48 core_stratum, /* Core dump files */
49 process_stratum /* Executing processes */
50 };
51
52 struct target_ops
53 {
54 char *to_shortname; /* Name this target type */
55 char *to_longname; /* Name for printing */
56 char *to_doc; /* Documentation. Does not include trailing
57 newline, and starts with a one-line descrip-
58 tion (probably similar to to_longname). */
59 void (*to_open) PARAMS ((char *, int));
60 void (*to_close) PARAMS ((int));
61 void (*to_attach) PARAMS ((char *, int));
62 void (*to_detach) PARAMS ((char *, int));
63 void (*to_resume) PARAMS ((int, int));
64 int (*to_wait) PARAMS ((int *));
65 void (*to_fetch_registers) PARAMS ((int));
66 void (*to_store_registers) PARAMS ((int));
67 void (*to_prepare_to_store) PARAMS ((void));
68 int (*to_xfer_memory) PARAMS ((CORE_ADDR, char *, int, int,
69 struct target_ops *));
70 void (*to_files_info) PARAMS ((struct target_ops *));
71 int (*to_insert_breakpoint) PARAMS ((CORE_ADDR, char *));
72 int (*to_remove_breakpoint) PARAMS ((CORE_ADDR, char *));
73 void (*to_terminal_init) PARAMS ((void));
74 void (*to_terminal_inferior) PARAMS ((void));
75 void (*to_terminal_ours_for_output) PARAMS ((void));
76 void (*to_terminal_ours) PARAMS ((void));
77 void (*to_terminal_info) PARAMS ((char *, int));
78 void (*to_kill) PARAMS ((void));
79 void (*to_load) PARAMS ((char *, int));
80 int (*to_lookup_symbol) PARAMS ((char *, CORE_ADDR *));
81 void (*to_create_inferior) PARAMS ((char *, char *, char **));
82 void (*to_mourn_inferior) PARAMS ((void));
83 enum strata to_stratum;
84 struct target_ops
85 *to_next;
86 int to_has_all_memory;
87 int to_has_memory;
88 int to_has_stack;
89 int to_has_registers;
90 int to_has_execution;
91 struct section_table
92 *to_sections;
93 struct section_table
94 *to_sections_end;
95 int to_magic;
96 /* Need sub-structure for target machine related rather than comm related? */
97 };
98
99 /* Magic number for checking ops size. If a struct doesn't end with this
100 number, somebody changed the declaration but didn't change all the
101 places that initialize one. */
102
103 #define OPS_MAGIC 3840
104
105 /* The ops structure for our "current" target process. */
106
107 extern struct target_ops *current_target;
108
109 /* Define easy words for doing these operations on our current target. */
110
111 #define target_shortname (current_target->to_shortname)
112 #define target_longname (current_target->to_longname)
113
114 /* The open routine takes the rest of the parameters from the command,
115 and (if successful) pushes a new target onto the stack.
116 Targets should supply this routine, if only to provide an error message. */
117 #define target_open(name, from_tty) \
118 (*current_target->to_open) (name, from_tty)
119
120 /* Does whatever cleanup is required for a target that we are no longer
121 going to be calling. Argument says whether we are quitting gdb and
122 should not get hung in case of errors, or whether we want a clean
123 termination even if it takes a while. This routine is automatically
124 always called just before a routine is popped off the target stack.
125 Closing file descriptors and freeing memory are typical things it should
126 do. */
127
128 #define target_close(quitting) \
129 (*current_target->to_close) (quitting)
130
131 /* Attaches to a process on the target side. */
132
133 #define target_attach(args, from_tty) \
134 (*current_target->to_attach) (args, from_tty)
135
136 /* Takes a program previously attached to and detaches it.
137 The program may resume execution (some targets do, some don't) and will
138 no longer stop on signals, etc. We better not have left any breakpoints
139 in the program or it'll die when it hits one. ARGS is arguments
140 typed by the user (e.g. a signal to send the process). FROM_TTY
141 says whether to be verbose or not. */
142
143 #define target_detach(args, from_tty) \
144 (*current_target->to_detach) (args, from_tty)
145
146 /* Resume execution of the target process. STEP says whether to single-step
147 or to run free; SIGGNAL is the signal value (e.g. SIGINT) to be given
148 to the target, or zero for no signal. */
149
150 #define target_resume(step, siggnal) \
151 (*current_target->to_resume) (step, siggnal)
152
153 /* Wait for inferior process to do something. Return pid of child,
154 or -1 in case of error; store status through argument pointer STATUS. */
155
156 #define target_wait(status) \
157 (*current_target->to_wait) (status)
158
159 /* Fetch register REGNO, or all regs if regno == -1. No result. */
160
161 #define target_fetch_registers(regno) \
162 (*current_target->to_fetch_registers) (regno)
163
164 /* Store at least register REGNO, or all regs if REGNO == -1.
165 It can store as many registers as it wants to, so the entire registers
166 array must be valid. Result is 0 for success, -1 for problems. */
167
168 #define target_store_registers(regs) \
169 (*current_target->to_store_registers) (regs)
170
171 /* Get ready to modify the registers array. On machines which store
172 individual registers, this doesn't need to do anything. On machines
173 which store all the registers in one fell swoop, this makes sure
174 that REGISTERS contains all the registers from the program being
175 debugged. */
176
177 #define target_prepare_to_store() \
178 (*current_target->to_prepare_to_store) ()
179
180 /* Reading and writing memory actually happens through a glue
181 function which iterates across the various targets. Result is
182 0 for success, or an errno value. */
183
184 extern int
185 target_read_string PARAMS ((CORE_ADDR, char *, int));
186
187 extern int
188 target_read_memory PARAMS ((CORE_ADDR, char *, int));
189
190 extern int
191 target_write_memory PARAMS ((CORE_ADDR, char *, int));
192
193 extern int
194 xfer_memory PARAMS ((CORE_ADDR, char *, int, int, struct target_ops *));
195
196 extern int
197 child_xfer_memory PARAMS ((CORE_ADDR, char *, int, int, struct target_ops *));
198
199 extern int
200 target_xfer_memory PARAMS ((CORE_ADDR, char *, int, int));
201
202 /* From exec.c */
203
204 extern void
205 print_section_info PARAMS ((struct target_ops *, bfd *));
206
207 /* Print a line about the current target. */
208
209 #define target_files_info() \
210 (*current_target->to_files_info) (current_target)
211
212 /* Insert a breakpoint at address ADDR in the target machine.
213 SAVE is a pointer to memory allocated for saving the
214 target contents. It is guaranteed by the caller to be long enough
215 to save "sizeof BREAKPOINT" bytes. Result is 0 for success, or
216 an errno value. */
217
218 #define target_insert_breakpoint(addr, save) \
219 (*current_target->to_insert_breakpoint) (addr, save)
220
221 /* Remove a breakpoint at address ADDR in the target machine.
222 SAVE is a pointer to the same save area
223 that was previously passed to target_insert_breakpoint.
224 Result is 0 for success, or an errno value. */
225
226 #define target_remove_breakpoint(addr, save) \
227 (*current_target->to_remove_breakpoint) (addr, save)
228
229 /* Initialize the terminal settings we record for the inferior,
230 before we actually run the inferior. */
231
232 #define target_terminal_init() \
233 (*current_target->to_terminal_init) ()
234
235 /* Put the inferior's terminal settings into effect.
236 This is preparation for starting or resuming the inferior. */
237
238 #define target_terminal_inferior() \
239 (*current_target->to_terminal_inferior) ()
240
241 /* Put some of our terminal settings into effect,
242 enough to get proper results from our output,
243 but do not change into or out of RAW mode
244 so that no input is discarded.
245
246 After doing this, either terminal_ours or terminal_inferior
247 should be called to get back to a normal state of affairs. */
248
249 #define target_terminal_ours_for_output() \
250 (*current_target->to_terminal_ours_for_output) ()
251
252 /* Put our terminal settings into effect.
253 First record the inferior's terminal settings
254 so they can be restored properly later. */
255
256 #define target_terminal_ours() \
257 (*current_target->to_terminal_ours) ()
258
259 /* Print useful information about our terminal status, if such a thing
260 exists. */
261
262 #define target_terminal_info(arg, from_tty) \
263 (*current_target->to_terminal_info) (arg, from_tty)
264
265 /* Kill the inferior process. Make it go away. */
266
267 #define target_kill() \
268 (*current_target->to_kill) ()
269
270 /* Load an executable file into the target process. This is expected to
271 not only bring new code into the target process, but also to update
272 GDB's symbol tables to match. */
273
274 #define target_load(arg, from_tty) \
275 (*current_target->to_load) (arg, from_tty)
276
277 /* Look up a symbol in the target's symbol table. NAME is the symbol
278 name. ADDRP is a CORE_ADDR * pointing to where the value of the symbol
279 should be returned. The result is 0 if successful, nonzero if the
280 symbol does not exist in the target environment. This function should
281 not call error() if communication with the target is interrupted, since
282 it is called from symbol reading, but should return nonzero, possibly
283 doing a complain(). */
284
285 #define target_lookup_symbol(name, addrp) \
286 (*current_target->to_lookup_symbol) (name, addrp)
287
288 /* Start an inferior process and set inferior_pid to its pid.
289 EXEC_FILE is the file to run.
290 ALLARGS is a string containing the arguments to the program.
291 ENV is the environment vector to pass. Errors reported with error().
292 On VxWorks and various standalone systems, we ignore exec_file. */
293
294 #define target_create_inferior(exec_file, args, env) \
295 (*current_target->to_create_inferior) (exec_file, args, env)
296
297 /* The inferior process has died. Do what is right. */
298
299 #define target_mourn_inferior() \
300 (*current_target->to_mourn_inferior) ()
301
302 /* Pointer to next target in the chain, e.g. a core file and an exec file. */
303
304 #define target_next \
305 (current_target->to_next)
306
307 /* Does the target include all of memory, or only part of it? This
308 determines whether we look up the target chain for other parts of
309 memory if this target can't satisfy a request. */
310
311 #define target_has_all_memory \
312 (current_target->to_has_all_memory)
313
314 /* Does the target include memory? (Dummy targets don't.) */
315
316 #define target_has_memory \
317 (current_target->to_has_memory)
318
319 /* Does the target have a stack? (Exec files don't, VxWorks doesn't, until
320 we start a process.) */
321
322 #define target_has_stack \
323 (current_target->to_has_stack)
324
325 /* Does the target have registers? (Exec files don't.) */
326
327 #define target_has_registers \
328 (current_target->to_has_registers)
329
330 /* Does the target have execution? Can we make it jump (through hoops),
331 or pop its stack a few times? */
332
333 #define target_has_execution \
334 (current_target->to_has_execution)
335
336 /* Routines for maintenance of the target structures...
337
338 add_target: Add a target to the list of all possible targets.
339
340 push_target: Make this target the top of the stack of currently used
341 targets, within its particular stratum of the stack. Result
342 is 0 if now atop the stack, nonzero if not on top (maybe
343 should warn user).
344
345 unpush_target: Remove this from the stack of currently used targets,
346 no matter where it is on the list. Returns 0 if no
347 change, 1 if removed from stack.
348
349 pop_target: Remove the top thing on the stack of current targets. */
350
351 extern void
352 add_target PARAMS ((struct target_ops *));
353
354 extern int
355 push_target PARAMS ((struct target_ops *));
356
357 extern int
358 unpush_target PARAMS ((struct target_ops *));
359
360 extern void
361 target_preopen PARAMS ((int));
362
363 extern void
364 pop_target PARAMS ((void));
365
366 /* Struct section_table maps address ranges to file sections. It is
367 mostly used with BFD files, but can be used without (e.g. for handling
368 raw disks, or files not in formats handled by BFD). */
369
370 struct section_table {
371 CORE_ADDR addr; /* Lowest address in section */
372 CORE_ADDR endaddr; /* 1+highest address in section */
373 sec_ptr sec_ptr; /* BFD section pointer */
374 bfd *bfd; /* BFD file pointer */
375 };
376
377 /* Builds a section table, given args BFD, SECTABLE_PTR, SECEND_PTR.
378 Returns 0 if OK, 1 on error. */
379
380 extern int
381 build_section_table PARAMS ((bfd *, struct section_table **,
382 struct section_table **));
383
384 /* From mem-break.c */
385
386 extern int
387 memory_remove_breakpoint PARAMS ((CORE_ADDR, char *));
388
389 extern int
390 memory_insert_breakpoint PARAMS ((CORE_ADDR, char *));
391
392 /* From target.c */
393
394 void
395 noprocess PARAMS ((void));
396
397 #endif /* !defined (TARGET_H) */
This page took 0.037265 seconds and 4 git commands to generate.