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