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.
5 This file is part of GDB.
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.
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.
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. */
21 #if !defined (TARGET_H)
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
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
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 */
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 int (*to_can_run
) PARAMS ((void));
84 enum strata to_stratum
;
87 int to_has_all_memory
;
97 /* Need sub-structure for target machine related rather than comm related? */
100 /* Magic number for checking ops size. If a struct doesn't end with this
101 number, somebody changed the declaration but didn't change all the
102 places that initialize one. */
104 #define OPS_MAGIC 3840
106 /* The ops structure for our "current" target process. */
108 extern struct target_ops
*current_target
;
110 /* Define easy words for doing these operations on our current target. */
112 #define target_shortname (current_target->to_shortname)
113 #define target_longname (current_target->to_longname)
115 /* The open routine takes the rest of the parameters from the command,
116 and (if successful) pushes a new target onto the stack.
117 Targets should supply this routine, if only to provide an error message. */
118 #define target_open(name, from_tty) \
119 (*current_target->to_open) (name, from_tty)
121 /* Does whatever cleanup is required for a target that we are no longer
122 going to be calling. Argument says whether we are quitting gdb and
123 should not get hung in case of errors, or whether we want a clean
124 termination even if it takes a while. This routine is automatically
125 always called just before a routine is popped off the target stack.
126 Closing file descriptors and freeing memory are typical things it should
129 #define target_close(quitting) \
130 (*current_target->to_close) (quitting)
132 /* Attaches to a process on the target side. Arguments are as passed
133 to the `attach' command by the user. This routine can be called
134 when the target is not on the target-stack, if the target_can_run
135 routine returns 1; in that case, it must push itself onto the stack.
136 Upon exit, the target should be ready for normal operations, and
137 should be ready to deliver the status of the process immediately
138 (without waiting) to an upcoming target_wait call. */
140 #define target_attach(args, from_tty) \
141 (*current_target->to_attach) (args, from_tty)
143 /* Takes a program previously attached to and detaches it.
144 The program may resume execution (some targets do, some don't) and will
145 no longer stop on signals, etc. We better not have left any breakpoints
146 in the program or it'll die when it hits one. ARGS is arguments
147 typed by the user (e.g. a signal to send the process). FROM_TTY
148 says whether to be verbose or not. */
150 #define target_detach(args, from_tty) \
151 (*current_target->to_detach) (args, from_tty)
153 /* Resume execution of the target process. STEP says whether to single-step
154 or to run free; SIGGNAL is the signal value (e.g. SIGINT) to be given
155 to the target, or zero for no signal. */
157 #define target_resume(step, siggnal) \
158 (*current_target->to_resume) (step, siggnal)
160 /* Wait for inferior process to do something. Return pid of child,
161 or -1 in case of error; store status through argument pointer STATUS. */
163 #define target_wait(status) \
164 (*current_target->to_wait) (status)
166 /* Fetch register REGNO, or all regs if regno == -1. No result. */
168 #define target_fetch_registers(regno) \
169 (*current_target->to_fetch_registers) (regno)
171 /* Store at least register REGNO, or all regs if REGNO == -1.
172 It can store as many registers as it wants to, so the entire registers
173 array must be valid. Result is 0 for success, -1 for problems. */
175 #define target_store_registers(regs) \
176 (*current_target->to_store_registers) (regs)
178 /* Get ready to modify the registers array. On machines which store
179 individual registers, this doesn't need to do anything. On machines
180 which store all the registers in one fell swoop, this makes sure
181 that REGISTERS contains all the registers from the program being
184 #define target_prepare_to_store() \
185 (*current_target->to_prepare_to_store) ()
187 /* Reading and writing memory actually happens through a glue
188 function which iterates across the various targets. Result is
189 0 for success, or an errno value. */
192 target_read_string
PARAMS ((CORE_ADDR
, char *, int));
195 target_read_memory
PARAMS ((CORE_ADDR
, char *, int));
198 target_write_memory
PARAMS ((CORE_ADDR
, char *, int));
201 xfer_memory
PARAMS ((CORE_ADDR
, char *, int, int, struct target_ops
*));
204 child_xfer_memory
PARAMS ((CORE_ADDR
, char *, int, int, struct target_ops
*));
207 target_xfer_memory
PARAMS ((CORE_ADDR
, char *, int, int));
212 print_section_info
PARAMS ((struct target_ops
*, bfd
*));
214 /* Print a line about the current target. */
216 #define target_files_info() \
217 (*current_target->to_files_info) (current_target)
219 /* Insert a breakpoint at address ADDR in the target machine.
220 SAVE is a pointer to memory allocated for saving the
221 target contents. It is guaranteed by the caller to be long enough
222 to save "sizeof BREAKPOINT" bytes. Result is 0 for success, or
225 #define target_insert_breakpoint(addr, save) \
226 (*current_target->to_insert_breakpoint) (addr, save)
228 /* Remove a breakpoint at address ADDR in the target machine.
229 SAVE is a pointer to the same save area
230 that was previously passed to target_insert_breakpoint.
231 Result is 0 for success, or an errno value. */
233 #define target_remove_breakpoint(addr, save) \
234 (*current_target->to_remove_breakpoint) (addr, save)
236 /* Initialize the terminal settings we record for the inferior,
237 before we actually run the inferior. */
239 #define target_terminal_init() \
240 (*current_target->to_terminal_init) ()
242 /* Put the inferior's terminal settings into effect.
243 This is preparation for starting or resuming the inferior. */
245 #define target_terminal_inferior() \
246 (*current_target->to_terminal_inferior) ()
248 /* Put some of our terminal settings into effect,
249 enough to get proper results from our output,
250 but do not change into or out of RAW mode
251 so that no input is discarded.
253 After doing this, either terminal_ours or terminal_inferior
254 should be called to get back to a normal state of affairs. */
256 #define target_terminal_ours_for_output() \
257 (*current_target->to_terminal_ours_for_output) ()
259 /* Put our terminal settings into effect.
260 First record the inferior's terminal settings
261 so they can be restored properly later. */
263 #define target_terminal_ours() \
264 (*current_target->to_terminal_ours) ()
266 /* Print useful information about our terminal status, if such a thing
269 #define target_terminal_info(arg, from_tty) \
270 (*current_target->to_terminal_info) (arg, from_tty)
272 /* Kill the inferior process. Make it go away. */
274 #define target_kill() \
275 (*current_target->to_kill) ()
277 /* Load an executable file into the target process. This is expected to
278 not only bring new code into the target process, but also to update
279 GDB's symbol tables to match. */
281 #define target_load(arg, from_tty) \
282 (*current_target->to_load) (arg, from_tty)
284 /* Look up a symbol in the target's symbol table. NAME is the symbol
285 name. ADDRP is a CORE_ADDR * pointing to where the value of the symbol
286 should be returned. The result is 0 if successful, nonzero if the
287 symbol does not exist in the target environment. This function should
288 not call error() if communication with the target is interrupted, since
289 it is called from symbol reading, but should return nonzero, possibly
290 doing a complain(). */
292 #define target_lookup_symbol(name, addrp) \
293 (*current_target->to_lookup_symbol) (name, addrp)
295 /* Start an inferior process and set inferior_pid to its pid.
296 EXEC_FILE is the file to run.
297 ALLARGS is a string containing the arguments to the program.
298 ENV is the environment vector to pass. Errors reported with error().
299 On VxWorks and various standalone systems, we ignore exec_file. */
301 #define target_create_inferior(exec_file, args, env) \
302 (*current_target->to_create_inferior) (exec_file, args, env)
304 /* The inferior process has died. Do what is right. */
306 #define target_mourn_inferior() \
307 (*current_target->to_mourn_inferior) ()
309 /* Does target have enough data to do a run or attach command? */
311 #define target_can_run(t) \
314 /* Pointer to next target in the chain, e.g. a core file and an exec file. */
316 #define target_next \
317 (current_target->to_next)
319 /* Does the target include all of memory, or only part of it? This
320 determines whether we look up the target chain for other parts of
321 memory if this target can't satisfy a request. */
323 #define target_has_all_memory \
324 (current_target->to_has_all_memory)
326 /* Does the target include memory? (Dummy targets don't.) */
328 #define target_has_memory \
329 (current_target->to_has_memory)
331 /* Does the target have a stack? (Exec files don't, VxWorks doesn't, until
332 we start a process.) */
334 #define target_has_stack \
335 (current_target->to_has_stack)
337 /* Does the target have registers? (Exec files don't.) */
339 #define target_has_registers \
340 (current_target->to_has_registers)
342 /* Does the target have execution? Can we make it jump (through hoops),
343 or pop its stack a few times? */
345 #define target_has_execution \
346 (current_target->to_has_execution)
348 /* Routines for maintenance of the target structures...
350 add_target: Add a target to the list of all possible targets.
352 push_target: Make this target the top of the stack of currently used
353 targets, within its particular stratum of the stack. Result
354 is 0 if now atop the stack, nonzero if not on top (maybe
357 unpush_target: Remove this from the stack of currently used targets,
358 no matter where it is on the list. Returns 0 if no
359 change, 1 if removed from stack.
361 pop_target: Remove the top thing on the stack of current targets. */
364 add_target
PARAMS ((struct target_ops
*));
367 push_target
PARAMS ((struct target_ops
*));
370 unpush_target
PARAMS ((struct target_ops
*));
373 target_preopen
PARAMS ((int));
376 pop_target
PARAMS ((void));
378 /* Struct section_table maps address ranges to file sections. It is
379 mostly used with BFD files, but can be used without (e.g. for handling
380 raw disks, or files not in formats handled by BFD). */
382 struct section_table
{
383 CORE_ADDR addr
; /* Lowest address in section */
384 CORE_ADDR endaddr
; /* 1+highest address in section */
385 sec_ptr sec_ptr
; /* BFD section pointer */
386 bfd
*bfd
; /* BFD file pointer */
389 /* Builds a section table, given args BFD, SECTABLE_PTR, SECEND_PTR.
390 Returns 0 if OK, 1 on error. */
393 build_section_table
PARAMS ((bfd
*, struct section_table
**,
394 struct section_table
**));
396 /* From mem-break.c */
399 memory_remove_breakpoint
PARAMS ((CORE_ADDR
, char *));
402 memory_insert_breakpoint
PARAMS ((CORE_ADDR
, char *));
407 noprocess
PARAMS ((void));
410 find_default_attach
PARAMS ((char *, int));
413 find_default_create_inferior
PARAMS ((char *, char *, char **));
415 #endif /* !defined (TARGET_H) */